package com.ll.generic;

/**
 * @author 刘龙
 * @version 1.0
 */
// 实现Comparable接口
public class MyDate implements Comparable<MyDate>{
    private Integer year;
    private Integer month;
    private Integer day;

    public MyDate(Integer year, Integer month, Integer day) {
        this.year = year;
        this.month = month;
        this.day = day;
    }

    public Integer getYear() {
        return year;
    }

    public void setYear(Integer year) {
        this.year = year;
    }

    public Integer getMonth() {
        return month;
    }

    public void setMonth(Integer month) {
        this.month = month;
    }

    public Integer getDay() {
        return day;
    }

    public void setDay(Integer day) {
        this.day = day;
    }

    @Override
    public String toString() {
        return "MyDate{" +
                "year=" + year +
                ", month=" + month +
                ", day=" + day +
                '}';
    }

    /**
     * 把对year,month,day比较放在这里
     * @param o
     * @return
     */
    @Override
    public int compareTo(MyDate o) {
        int yearMinus = year - o.getYear();
        if (yearMinus != 0 ) {
            return yearMinus;
        }

        // 如果year相同,就比较month
        int monthMinus = month - o.getMonth();
        if (monthMinus != 0) {
            return monthMinus;
        }

        //如果year和month相同,就比较day
        int dayMinus = day - o.getDay();
        return dayMinus;
    }
}
